package services.contact_api
{
	import com.adobe.fiber.core.model_internal;
	import com.adobe.fiber.services.wrapper.WebServiceWrapper;
	
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.soap.mxml.Operation;
	import mx.rpc.soap.mxml.WebService;	

	internal class ContactAPI_Base extends  com.adobe.fiber.services.wrapper.WebServiceWrapper
	{
		public function ContactAPI_Base()
		{			
			//_serviceControl = new mx.rpc.soap.WebService();
			super._serviceControl = new mx.rpc.soap.mxml.WebService();
			var operations:Array = new Array();
			var operation:Operation;
			var argsArray:Array;
			
			operation = new Operation(null, "GetContact");
			argsArray = new Array("memberId");
			operation.resultType = Object;
			operation.arguments = argsArray;
			operations.push(operation);
			
			operation = new Operation(null, "GetHistory");
			argsArray = new Array("memberId");
			operation.resultType = Object;
			operation.arguments = argsArray;
			operations.push(operation);
			
			_serviceControl.wsdl = "http://localhost:8080/Cineplex.Contacts/ContactServices.asmx";
			_serviceControl.operations = operations;
			
//			_serviceControl.addEventListener("fault", faultHandler);
//			_serviceControl.addEventListener(ResultEvent.RESULT, resultHandler);
			_serviceControl.loadWSDL();			
			
			preInitializeService();
			model_internal::initialize();
		}
		
		public function resultHandler(event:ResultEvent):void {			
			var retInt:Object = event.result;
			Alert.show(retInt.toString());
		}
		
		public function faultHandler(event:FaultEvent):void {
			//deal with event.fault.faultString, etc
		}
		
		//init initialization routine here, child class to override
		protected function preInitializeService():void
		{
			
		}
		
		/**
		 * This method is a generated wrapper used to call the 'GetHistory' operation. It returns an mx.rpc.AsyncToken whose 
		 * result property will be populated with the result of the operation when the server response is received. 
		 * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. 
		 * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
		 *
		 * @see mx.rpc.AsyncToken
		 * @see mx.rpc.CallResponder 
		 *
		 * @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
		 */
		public function GetHistory(memberId:String) : mx.rpc.AsyncToken
		{
			var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("GetHistory");
			var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(memberId) ;
			return _internal_token;
		}
		
		/**
		 * This method is a generated wrapper used to call the 'GetContact' operation. It returns an mx.rpc.AsyncToken whose 
		 * result property will be populated with the result of the operation when the server response is received. 
		 * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. 
		 * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
		 *
		 * @see mx.rpc.AsyncToken
		 * @see mx.rpc.CallResponder 
		 *
		 * @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
		 */
		public function GetContact(memberId:String) : mx.rpc.AsyncToken
		{
			var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("GetContact");
			var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(memberId) ;
			return _internal_token;
		}
	}
}